﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
using System.Web.Mvc;
using CMS.Web.Data;

namespace CMS.Web.Engine
{       
    [Widget(Guid = "8444d599-4a61-4609-994a-f1555356096f",
       Name = "HTML-контент",
       Category = "Контент",
       PartialViewName = "~/Widgets/Html/Default.cshtml", 
       Description = "Редактируемая HTML-врезка на странице.")]
    public class WidgetHtml : WidgetBase
    {
        public WidgetHtml()
        {
            this.Settings = new WidgetHtmlSettings();
        }
        public override void Initialize(string serializedSettings, IEnumerable<string> ids)
        {
            if (!serializedSettings.IsEmpty())
                this.Settings = Json.Deserialize<WidgetHtmlSettings>(serializedSettings);          

            this.Model = new WidgetModelHtml
            {
                X = (this.Settings as WidgetHtmlSettings).Setting1.Convert<int>(),
                Y = (this.Settings as WidgetHtmlSettings).Setting2.Convert<int>(),
                Widget = this.ID
            };
        }            
    }

    public class WidgetModelHtml : WidgetModel
    {
        public int X { get; set; }
        public int Y { get; set; }
        public int Z { get { return X * Y; } }
    }

    public class WidgetHtmlSettings : WidgetSettings
    {
        [WidgetSetting("X", "Начальное значение X")]
        public string Setting1 { get; set; }

        [WidgetSetting("Y", "Начальное значение Y")]
        public string Setting2 { get; set; }
    }    
}